import pyOsi

#Create a problem pointer.  We use the base class here.
theSI = pyOsi.getOsi("CLP")


#Read in an mps file.  This one's from the MIPLIB library.
#si->readMps("../../Data/Sample/p0033");
theSI.readMps("p0033")

#Display some information about the instance
nrows = theSI.getNumRows()
ncols = theSI.getNumCols()
nelem = theSI.getNumElements()
print "This problem has %d rows, %d  columns, and %d  nonzeros." % (nrows ,ncols ,nelem)

upper_bounds = theSI.getColUpper()
print "The upper bound on the first column is %f" % upper_bounds[0]

#Before solving, indicate some parameters
theSI.setIntParam( pyOsi.OsiIntParam.OsiMaxNumIteration, 10)
theSI.setDblParam( pyOsi.OsiDblParam.OsiPrimalTolerance, 0.001 )

theSI.initialSolve()

#Check the solution
if theSI.isProvenOptimal():
      print "Found optimal solution!" 
      print "Objective value is %f " % theSI.getObjValue()
      #Examine solution
      n = theSI.getNumCols()
      solution = theSI.getColSolution()

      print "Solution: "
      for i in xrange(n):
        print solution[i]
     
      print  "It took %d iterations to solve." % theSI.getIterationCount()
else: 
      print "Didn't find optimal solution."

      if theSI.isProvenPrimalInfeasible():
        print "Problem is proven to be infeasible."
      if theSI.isProvenDualInfeasible():
        print "Problem is proven dual infeasible."
      if theSI.isIterationLimitReached():
        print "Reached iteration limit."


